var glob = require('glob')
var path = require('path');
function initRouterSystem(app){
    var routerFiles = glob.sync(__dirname+'/*.js', {ignore:'**/index.js'})

    for(var i = 0;i<routerFiles.length;i++){
        var filePath = routerFiles[i]
        var routerObj = require(filePath)
        var router = routerObj.createRouter();
        var ns = routerObj.ns || path.basename(filePath,'.js')
        if(ns.charAt(0)!=='/'){ns='/'+ns}
        app.use(ns,router)
    }
}

module.exports = {
    initRouterSystem:initRouterSystem
};